package org.linlinjava.litemall.admin.web.order_manage;

import org.linlinjava.litemall.admin.service.order_manage.AgedmallOrderAfterSaleService;
import org.linlinjava.litemall.admin.vo.order_manage.AfterSaleRefusedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@RestController
@RequestMapping("/order/afterSale")
public class AgedmallOrderAfterSaleController {

    @Autowired
    private AgedmallOrderAfterSaleService agedmallOrderAfterSaleService;

    /**
     * 获取售后维权列表
     */
    @PostMapping("/orderList")
    public Object orderList(@RequestParam(required = false) Integer searchType,
                            @RequestParam(required = false) String searchValue,
                       @RequestParam(required = false) Integer state,
                       @RequestParam(required = false) Integer provinceId,
                       @RequestParam(required = false) Integer cityId,
                       @RequestParam(required = false) Integer storeId,
                       @RequestParam(required = false) LocalDateTime startTime,
                       @RequestParam(required = false) LocalDateTime endTime,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit){
        return agedmallOrderAfterSaleService.orderList(searchType, searchValue, state, provinceId, cityId, storeId, startTime, endTime, page, limit);
    }

    /**
     * 点击同意、修改、修改金额
     */
    @PostMapping("/button")
    public Object button(@RequestParam Integer id,
                            @RequestParam Integer state,
                            @RequestParam(required = false) BigDecimal amount,
                            @RequestParam(required = false) String reason){
        return agedmallOrderAfterSaleService.button(id, state, amount, reason);
    }

    /**
     * 点击备注提交
     */
    @PostMapping("/remark")
    public Object remark(@RequestParam Integer id,
                         @RequestParam String remark){
        return agedmallOrderAfterSaleService.remark(id, remark);
    }

    /**
     * 点击确认收货
     */
    @PostMapping("/receivedCommodity")
    public Object receivedCommodity(@RequestParam Integer id,
                         @RequestParam Integer commodityId){
        return agedmallOrderAfterSaleService.receivedCommodity(id, commodityId);
    }

    /**
     * 根据不同的售后订单状态加载订单详情页
     */
    @PostMapping("/orderDetail")
    public Object orderDetail(@RequestParam Integer afterSaleId){
        return agedmallOrderAfterSaleService.orderDetail(afterSaleId);
    }

    /**
     * 售后商品明细
     */
    @PostMapping("/pickupDetail")
    public Object pickupDetail(@RequestParam Integer afterSaleId){
        return agedmallOrderAfterSaleService.pickupDetail(afterSaleId);
    }

    /**
     * 点击收货
     */
    @PostMapping("/pickup")
    public Object pickup(@RequestParam Integer afterSaleId,
                         @RequestParam Integer ship,
                         @RequestParam(required = false) Integer deliveryManId,
                         @RequestParam(required = false) String expressCompany,
                         @RequestParam(required = false) String expressCode){
        return agedmallOrderAfterSaleService.pickup(afterSaleId, ship, deliveryManId, expressCompany, expressCode);
    }

    /**
     * 点击发货
     */
    @PostMapping("/ship")
    public Object ship(@RequestParam Integer afterSaleId,
                         @RequestParam Integer ship,
                         @RequestParam(required = false) Integer deliveryManId,
                         @RequestParam(required = false) String expressCompany,
                         @RequestParam(required = false) String expressCode,
                         @RequestParam Integer shipPriceType){
        return agedmallOrderAfterSaleService.ship(afterSaleId, ship, deliveryManId, expressCompany, expressCode, shipPriceType);
    }



    //2021年12月2日14:01:43 后新增

    /**
     * 审核通过
     * @param id aftersale表主键id
     */
    @PostMapping("/approved/{id}")
    public Object approved(@PathVariable  Integer id){
        return agedmallOrderAfterSaleService.approved(id);
    }


    /**
     * 审核拒绝
     */
    @PostMapping("/refused")
    public Object refused(@RequestBody AfterSaleRefusedVo afterSaleRefusedVo){
        return agedmallOrderAfterSaleService.refused(afterSaleRefusedVo);
    }

    /**
     * 售后确认收货-（退货退款收到货了，换货收到退的货）
     */
    @PostMapping("/confirmGoods/{id}")
    public Object confirmGoods(@PathVariable  Integer id){
        return agedmallOrderAfterSaleService.confirmGoods(id);
    }
}
